package edu.sctu.nieyu.day20150614.IOUtil;

import java.io.*;

/**
 * Created by user01 on 2015/6/14.
 */
public class InputStreamTest {

    public void getInputStream(){

        int countbyte = 0;
        int count = 0;

        FileInputStream fileInputStream;
        FileOutputStream fileOutputStream;
        byte[] bytes = new byte[1024];
        try{
            fileInputStream = new FileInputStream(new File("D://201112239263875961.jpg"));
            fileOutputStream = new FileOutputStream(new File("D://201112239263875961nn.jpg"));
            try {
                while ((countbyte = fileInputStream.read(bytes))!= -1){
                    fileOutputStream.write(bytes,0,countbyte);
                    count+= countbyte;
//                    /**
//                     * 字节流字符流的转换；
//                     */
//                    String text = new String(bytes);
//                    System.out.println(text);
//                    char[] chars = text.toCharArray();
//                    System.out.println(chars);
                }
                System.out.println(count);
            }catch (IOException e){
                e.printStackTrace();
            }
            try {
                fileInputStream.close();
                fileOutputStream.close();
            }catch (IOException e){
                e.printStackTrace();
            }
        }catch (FileNotFoundException e){
            e.printStackTrace();

        }
    }
    public void getInputStreamm(){

        int countbyte = 0;
        int count = 0;

        FileInputStream fileInputStream;
        FileOutputStream fileOutputStream;
        try {
            fileInputStream = new FileInputStream(new File("D://test//lianxi.txt"));
            fileOutputStream = new FileOutputStream(new File("D://test//lianxi2.txt"));

            try {
                while ((countbyte = fileInputStream.read())!=-1){
                    fileOutputStream.write(countbyte);
                    count+= countbyte;
                }
                System.out.println(count);
            }catch (IOException e){
                e.printStackTrace();
            }
            try {
                fileInputStream.close();
                fileOutputStream.close();
            }catch (IOException e){
                e.printStackTrace();
            }
        }catch (FileNotFoundException e){
            e.printStackTrace();
        }
    }
}
